package org.linlinjava.litemall.db.vo.app;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wj
 * @date 2022/2/9 14:04
 */
public class GoodsVipSalesDto {

    private Integer level;

    private BigDecimal price;

    private Integer limit;

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public GoodsVipSalesDto(Integer level, BigDecimal price, Integer limit) {
        this.level = level;
        this.price = price;
        this.limit = limit;
    }

    public static List<GoodsVipSalesDto> getVipSalesList(String vipJson) {
        List<GoodsVipSalesDto> goodsVipSalesDtoList=new ArrayList<>();
        JSONArray jsonArray = JSONArray.parseArray(vipJson);
        for (int i = 0; i < jsonArray.size(); i++) {
            GoodsVipSalesDto goodsVipSalesDto=new GoodsVipSalesDto();
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Integer level=Integer.parseInt(jsonObject.get("level").toString());
            BigDecimal price=new BigDecimal(jsonObject.get("price").toString());
            Integer limit=Integer.parseInt(jsonObject.get("number").toString());
            goodsVipSalesDto.setLevel(level);
            goodsVipSalesDto.setLimit(limit);
            goodsVipSalesDto.setPrice(price);
            goodsVipSalesDtoList.add(goodsVipSalesDto);
        }
        return goodsVipSalesDtoList;
    }

    public GoodsVipSalesDto() {
    }
}
